define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'card/index' + location.search,
                    add_url: 'card/add',
                    edit_url: 'card/edit',
                    del_url: 'card/del',
                    multi_url: 'card/multi',
                    import_url: 'card/import',
                    table: 'card',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                /*
                fixedColumns: true,
                fixedRightNumber: 1,
                */
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'card_name', title: __('Card_name'), operate: 'LIKE'},
                        {field: 'card_price', title: __('Card_price'), operate: false},
                        {field: 'card_service_term_day', title: __('Card_service_term_day'), operate: false},
                        {field: 'display_store_string', title: __('Store_ids'), operate: false},
                        {field: 'card_total_hour', title: __('Card_total_hour'), operate: false},
                        {field: 'card_display', title: __('Card_display'), searchList: {"0":__('Card_display 0'),"1":__('Card_display 1')}, formatter: Table.api.formatter.normal, operate: false},
                        {field: 'dzmt_dealgroupid', title: '大众美团对应的ID', operate: false},
                        {field: 'could_buy_number', title: __('Could_buy_number'), operate: false, formatter: Controller.api.showcouldbuynumber},
                        {field: 'weigh', title: __('排序'), operate: false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                searchFormVisible: true,
                search: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $("#c-store_ids").data("eOpen", function(){
                $('.sp_result_area').attr('style','width:500px')  
            });
            Controller.api.bindevent();
        },
        edit: function () {
            $("#c-store_ids").data("eOpen", function(){
                $('.sp_result_area').attr('style','width:500px')  
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            showcouldbuynumber: function (e) {
                if (0 == e) {
                    return '不限制'
                } else {
                    return e
                }
            }
        }
    };
    return Controller;
});
